package org.belkodevelop.realty.domen;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;
import org.belkodevelop.geocoding.adress.domen.CompositeAdress;
import org.belkodevelop.photo.domen.Photo;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

@Entity
@Table(name = "realty")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, length = 20)
@TypeDef(name = "compositeAdress", typeClass = org.belkodevelop.geocoding.adress.domen.type.CompositeAdressType.class)
public abstract class Realty implements Serializable {
    
    @Id
    @Column(name = "id")
    @GeneratedValue
    private long id;
    
    @Column(name = "description", length = 2000)
    private String description;
    
    @Column(name = "adress", nullable = false, length = 1000)
    private String adress; 
    
    @Type(type="text")
    @Column(name = "google_adress_json", nullable = false)
    private String googleAdressJSON;
    
    @Type(type = "compositeAdress")
    @Columns(columns = {
        @Column(name = "adr_room", length = 1000),
        @Column(name = "adr_floor", length = 1000),
        @Column(name = "adr_street_number", length = 1000),
        @Column(name = "adr_street_address", length = 1000),
        @Column(name = "adr_route", length = 1000),
        @Column(name = "adr_sublocality", length = 1000),
        @Column(name = "adr_locality", length = 1000),
        @Column(name = "adr_administrative_area_level_3", length = 1000),
        @Column(name = "adr_administrative_area_level_2", length = 1000),
        @Column(name = "adr_administrative_area_level_1", length = 1000),
        @Column(name = "adr_country", length = 1000)
    })
    private CompositeAdress compositeAdress;

    @Column(name="type", nullable=false, updatable=false, insertable=false)
    private String type;

    @OneToMany(mappedBy = "realty", cascade = CascadeType.ALL)
    private Set<Photo> photos;

    @OneToOne
    @JoinColumn(name = "main_photo_id")
    private Photo mainPhoto;

    public void setId(long id) {
        this.id = id;
    }
    
    public long getId() {
        return id;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setGoogleAdressJSON(String googleAdressJSON) {
        this.googleAdressJSON = googleAdressJSON;
    }
    
    public String getGoogleAdressJSON() {
        return googleAdressJSON;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public CompositeAdress getCompositeAdress() {
        return compositeAdress;
    }

    public void setCompositeAdress(CompositeAdress compositeAdress) {
        this.compositeAdress = compositeAdress;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Set<Photo> getPhotos() {
        return photos;
    }

    public void setPhotos(Set<Photo> photos) {
        this.photos = photos;
    }

    public Photo getMainPhoto() {
        return mainPhoto;
    }

    public void setMainPhoto(Photo mainPhoto) {
        this.mainPhoto = mainPhoto;
    }
}
